<template>
  <lb-layout
    v-loading="$store.getters.loading"
    element-loading-text="拼命加载中"
    element-loading-spinner="el-icon-loading"
    element-loading-background="#a19f9fb0;"
  >
    <aps-form
      :config="apsForm.formConfig"
      :model="apsForm.formData"
      :formRef="apsForm.formRef"
      :labelWidth="apsForm.labelWidth"
      ref="form"
    ></aps-form>
    <pannel-Title>
      <Title name="会商趋势分析" :line="false">
        <chart :data="chart" />
      </Title>
    </pannel-Title>
    <pannel-Title class="mt10">
      <Title name="会商研判记录" :line="false">
        <lb-table
          :column="tableData.column"
          :data="tableData.data"
          border
          height="330"
          background
          layout="total, sizes, prev, pager, next, jumper"
        >
        </lb-table>
      </Title>
    </pannel-Title>

    <component
      :is="modelName"
      :id="id"
      :visible.sync="show"
      @close="close"
    ></component>
  </lb-layout>
</template>

<script>
// import { getStatisticsList } from "@/api/donation/other";
import chart from "@/views/work/conference/consultation/components/chart.vue";
import detail from "@/views/work/conference/consultation/components/detail.vue";
import operate from "@/views/work/conference/consultation/components/operate.vue";

export default {
  dicts: ["server_type"],
  components: {
    operate,
    detail,
    chart,
  },
  name: "stream",
  data() {
    return {
      show: false,
      modelName: "",
      id: "",
      chart: {}, //图表数据
      apsForm: {
        formRef: "form",
        labelWidth: "150px",
        formData: {},
        formConfig: {
          formAttr: {
            inline: true,
            size: "small",
          },
          properties: {
            //这里是渲染查询表单的表头和类型的数据
            donationName: {
              typeName: "el-date-picker",
              type: "daterange",
              "start-placeholder": "开始日期",
              "end-placeholder": "结束日期",
            },

            asdasd: {
              typeName: "el-select",
              render: (h) => {
                let that = this;
                let arr = [];
                that.dict?.type?.server_type.some((item) => {
                  arr.push(item);
                });
                // 数据严谨处理,处理后端数据异常情况
                let valNum = that.$refs?.form?.getFieldsValue().serveShape;
                let a = [
                  h(
                    "el-select",
                    {
                      attrs: {
                        placeholder: "会商规范版本号",
                        value: valNum,
                      },
                      props: ["value"],
                      on: {
                        change: (value) => {
                          that.$refs?.form?.setFieldValue("serveShape", value);
                          that.$forceUpdate();
                        },
                      },
                    },
                    [
                      arr.map((item) => {
                        let { label, value } = item;
                        return h("el-option", {
                          props: {
                            label,
                            value: parseInt(value),
                            key: value,
                          },
                        });
                      }),
                    ]
                  ),
                ];
                return h("div", a);
              },
            },
          },
          formSoltButton: [
            {
              label: "搜索",
              type: "primary",
              typeName: "el-button",
              size: "small",
              icon: "el-icon-search",
              click: this.handlerSearchDetail,
            },
            {
              label: "重置",
              typeName: "el-button",
              size: "small",
              icon: "el-icon-refresh-left",
              click: this.handleReset,
            },
            {
              label: "新增",
              type: "primary",
              typeName: "el-button",
              plain: true,
              size: "small",
              icon: "el-icon-plus",
              click: () => this.showModel("operate", ""),
            },
          ],
        },
      },
      tableData: {
        column: [
          {
            prop: "donationName",
            label: "月份",
          },
          {
            prop: "donationSum",
            label: "部门",
          },
          {
            prop: "strokeCount",
            label: "是否及时",
          },
          {
            prop: "strokeCount",
            width: "120",
            label: "能耗（kwh）",
          },
          {
            prop: "strokeCount",
            width: "200",
            label: "额度超支率",
          },
          {
            prop: "strokeCount",
            label: "会商研判情况",
            showOverflowTooltip: true,
          },
          {
            prop: "strokeCount",
            label: "存在问题",
          },
          {
            prop: "strokeCount",
            label: "需要专班协调",
          },
          {
            label: "操作",
            width: "150",
            fixed: "right",
            render: (h, scope) => {
              let that = this;
              return (
                <div>
                  {
                    <el-button
                      type="text"
                      size="small"
                      icon="el-icon-view"
                      onClick={() => {
                        this.showModel("detail", scope.row);
                      }}
                    >
                      详情
                    </el-button>
                  }
                </div>
              );
            },
          },
        ],
        data: [],
      },
      currentPage: 1,
      pageSize: 10,
      total: 0,
    };
  },
  mounted() {
    // this.initData();
    this.getBudgetdata();
  },
  methods: {
    showModel(name, params) {
      this.modelName = name;
      this.id = params.id || "";
      this.show = true;
    },
    close(status) {
      this.show = false;
      setTimeout(() => {
        if (status) this.getList();
      }, 200);
    },
    getBudgetdata() {
      this.chart = {
        arr: [
          {
            name: "应会商次数",
            data: [0, 0, 0, 0, 0, 0, 0, 0],
            type: "bar",
          },
          {
            name: "实际会商次数",
            data: [0, 0, 0, 0, 0, 0, 0, 0],
            type: "bar",
          },
          {
            name: "未会商次数",
            data: [0, 0, 0, 0, 0, 0, 0, 0],
            type: "bar",
          },
          // {
          //   name: "应会商次数",
          //   data: [130, 209, 179, 217, 221, 118, 186, 228],
          //   type: "bar",
          // },
          // {
          //   name: "实际会商次数",
          //   data: [110, 200, 150, 80, 70, 110, 130, 193],
          //   type: "bar",
          // },
          // {
          //   name: "未会商次数",
          //   data: [110, 200, 150, 80, 70, 110, 130, 193],
          //   type: "bar",
          // },
        ],
        xData: ["5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"],
      };
    },
    handlerAudit(row) {
      this.auditShow = true;
    },
    close(status) {
      this.show = false;
      if (status) this.initData();
    },
    async initData(currentPage, pageSize, data) {
      return false;
      let that = this;
      let query = {
        donationName: "",
      };
      if (currentPage) {
        query.pageNum = currentPage;
      } else {
        query.pageNum = that.currentPage;
      }
      if (pageSize) {
        query.pageSize = pageSize;
      } else {
        query.pageSize = that.pageSize;
      }
      if (data) {
        query.donationName = data?.donationName ?? "";
      }
      this.$store.commit("app/updateApiCount", "add");
      await getStatisticsList(query)
        .then((res) => {
          this.$store.commit("app/updateApiCount");
          that.tableData.data = res.rows;
          that.total = res.total;
        })
        .catch((err) => {
          this.$store.commit("app/updateApiCount");
          // this.$message.error("系统错误,请联系管理员!10102");
        });
    },
    handlerSearchDetail(val) {
      //val===1 删除操作成功后分页边界值处理
      let data = {};
      let currentPage = 1;
      if (val === 1) {
        if (
          this.total === (this.currentPage - 1) * this.pageSize + 1 &&
          this.total !== 0 &&
          this.currentPage > 1
        ) {
          currentPage = this.currentPage - 1;
          this.currentPage = currentPage;
        } else {
          currentPage = this.currentPage;
        }
      } else {
        currentPage = this.currentPage;
      }
      data.donationName = this.$refs?.form?.getFieldsValue().donationName;
      this.initData(currentPage, this.pageSize, data);
    },
    handleOperDelete(status, row) {
      let that = this;
      let query = {},
        text = "";
      if (status === 0) {
        query.id = row.id;
        text = "是否确认删除" + (row?.name ?? "该条数据") + "？";
      } else if (status === 1) {
        query.id = this.multipleSelection.map((el) => {
          return el.id;
        });
        text = "是否确认进行批量删除？";
      }
      this.$store.commit("app/updateApiCount", "add");
      this.$modal
        .confirm(text)
        .then(() => {
          getDeleteVideo(query)
            .then((res) => {
              this.$store.commit("app/updateApiCount");
              if (res.code === 700) {
                that.$message.warning(res.msg);
                return false;
              }
              that.$message.success("已删除!");
              that.initData();
            })
            .catch((err) => {
              this.$store.commit("app/updateApiCount");
              // this.$message.error("系统错误,请联系管理员!10128");
            });
        })
        .catch(() => {
          this.$store.commit("app/updateApiCount");
        });
    },
    handleSizeChange(val) {
      this.currentPage = 1;
      this.pageSize = val;
      this.handlerSearchDetail();
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.handlerSearchDetail();
    },
    handleReset() {
      //重置
      this.$refs?.form?.resetFields();
      this.handlerSearchDetail();
    },
    // 批量删除
    handleDeleteAll() {
      if (this.multipleSelection.length > 0) {
        this.handleOperDelete(1);
      } else {
        this.$message.warning("请选择删除项");
      }
    },
    // 多选
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    // 新增
    handleAdd() {
      this.$router.push({ path: "src\viewsexportsecaindex.vue" });
    },
  },
};
</script>
<style>
.consultation {
  padding: 20px;
}
</style>
